<script>
/*airline*/
$('document').ready(function(){
	 $(document).on('change', '.flightclass', function() {
// 		 $(".flightclass").click(function (){
			//update the flightclass list
			if (this.checked)
			{
				//checkbox is checked
				var checkedValue = $(this).val();
				console.log(checkedValue+ " is checked");
				 for (i = 0; i < cabinclassArr.length; i++) {
					 if (cabinclassArr[i].name == checkedValue) {
				        	//flightclass already exist in list, just increase amount of carrier
				        	cabinclassArr[i].check=true;
				        	break;
				        }
				 }
			}
			else
			{
				//checkbox is unchecked
				//remove flightclass in airlines list
				var uncheckedValue = $(this).val();
				console.log(uncheckedValue+ " is unchecked");
				 for (i = 0; i < cabinclassArr.length; i++) {
					 if (cabinclassArr[i].name == uncheckedValue) {
				        	//flightclass already exist in list, mark it is unchecked
				        	
				        	cabinclassArr[i].check=false;
				            break;
				        }
				 }
			}
			//re load data
			console.log("flightclass: flightResult IN = "+flightResult.length);
			flightResult=response.filter(function(e){
				return compare(e);
			});
			console.log("flightclass: flightResult OUT = "+flightResult.length);
			$("#lastPostsLoader").empty();
		 	//uncheck all item in airline list
//	 	 	uncheckAirlines();
			loadData();
	 });
});

function getFlightClass(item){
	var flightclass=new Object();
	flightclass.value=item.outBound.departAirports[0].airline.flightClass;
	if(flightclass.value=="0"){
		flightclass.name="Economy";
	}else flightclass.name="Business";
	flightclass.amount=1;
	flightclass.check=true;
    var j;
    var check = false;
    for (j = 0; j < cabinclassArr.length; j++) {
        if (cabinclassArr[j].name == flightclass.name) {
        	//flightclass already exist in list, just increase amount of flightclass
        	cabinclassArr[j].amount=cabinclassArr[j].amount+1;
            check = true;
            break;
        }
    }
    if (check == false) {
    	//flightclass don't exist in list, push it into list
        cabinclassArr.push(flightclass);
    }
    if (item.roundTrip == true) {
    	//in case of round trip, i compare flightclass of inbound and flightclass of outbound, 
    	//if it equal, we ignore, otherwise, i continue loop to check if it already exist in list or not  
    	inboundName=item.inBound.departAirports[0].airline.name;
    	if (inboundName == flightclass.name )
    	{
    		return;
    	}
    	var flightclassIB=new Object();
    	flightclassIB.amount=1;
    	flightclassIB.name=inboundName;
        var check = false;
        for (j = 0; j < cabinclassArr.length; j++) {
            if (cabinclassArr[j].name == flightclassIB.name) {
            	cabinclassArr[j].amount=cabinclassArr[j].amount+1;
                check = true;
                break;
            }
        }
        if (check == false) {
            cabinclassArr.push(flightclassIB);
        }
    }
};
function resetAmountOfFlightClass()
{
	console.log("resetAmountOfFlightClass");
	for(i=0;i<cabinclassArr.length;i++)
	{
		cabinclassArr[i].amount=0;
	}
}
</script>